/** @format */
import { createRouter, createWebHistory } from 'vue-router'

// 导入 4 个一级页面组件
import Find from '@/views/Find.vue'
import My from '@/views/My.vue'
import Friend from '@/views/Friend.vue'
import _404 from '@/views/404.vue'

// 导入 3 个二级路由页面组件
import Recommend from '@/views/Recommend.vue'
import TopList from '@/views/TopList.vue'
import PlayList from '@/views/PlayList.vue'

const router = createRouter({
	history: createWebHistory(), // 历史模式
	routes: [
		{
			path: '/',
			redirect: '/find' // 重定向
		},
		{
			path: '/find',
			component: Find,
			redirect: '/find/recommend',
			// 配置路由嵌套
			children: [
				{
					// 推荐
					path: 'recommend', // 注意：二级路由开始，path 不加 / ，但是今后访问这个路由路径的时候，需要写完整路径
					component: Recommend
				},
				{
					// 排行榜
					path: 'toplist',
					component: TopList
				},
				{
					// 歌单
					path: 'playlist',
					component: PlayList
				}
			]
		},
		{
			path: '/my',
			component: My
		},
		{
			path: '/friend',
			name: 'Friend',
			component: Friend
		},
		{
			// 配置 404 规则
			path: '/:pathMatch(.*)*',
			component: _404
		}
	]
})

export default router
